#pragma once

#include<iostream>
#include<string>
#include<assert.h>
#include<algorithm>


using namespace std;

namespace wx
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;
		static const size_t npos;
		string(const char* str = "");
		string(const string& s);
		template<class inputiterator>
		string(inputiterator begin, inputiterator end)
		{
			auto it = begin;
			while(it!=end)
			{
				push_back(*it);
				it++;
			}
		}
		~string();
		iterator begin();
		iterator end();
		const_iterator begin() const;
		const_iterator end() const;
		const char* c_str() const;
		void reserve(size_t n);
		const size_t capacity() const;
		const size_t size() const;
		char& operator[](size_t pos);
		const char& operator[](size_t pos) const;
		void push_back(char c);
		string& append(const char* str);
		string& operator+=(char c);
		string& operator+=(const char* str);
		void pop_back();
		string& insert(size_t pos, char c);
		string& insert(size_t pos, const char* str);
		string& operator=(string s);
		void swap(string& s);
		string& erase(size_t pos = 0, size_t len = npos);
		size_t find(char c, size_t pos = 0) const;
		size_t find(const char* sub, size_t pos = 0) const;
		string substr(size_t pos, size_t len = npos) const;
		bool operator<(const string& s) const;
		bool operator<=(const string& s) const;
		bool operator>(const string& s) const;
		bool operator>=(const string& s) const;
		bool operator==(const string& s) const;
		bool operator!=(const string& s) const;
		void clear();
	private:
		char* _arr = new char[16];
		size_t _size = 0;
		size_t _capacity = 16;
	};

	std::ostream& operator<<(std::ostream& os, const string& s);
	std::istream& operator>>(std::istream& is, string& s);
}

